$(function() {
    $('.layui-plus').click(function() {
        layer_iframe('添加购买会员记录表', 'edit');
    });
    window.page = 1;
    window.limit = 10;
    window.options = {
        id: 'data_table',
        elem: '.layui-table.data-table',
        url: location.pathname + location.search,
        where: {},
        page: {
            curr: 1
        },
        limits: [10, 25, 50, 100],
        done: function(res, curr, first) {
            if (!res.data && curr > 1) {
                window.options.page.curr = curr - 1;
                window.tableIns.reload(window.options);
            }
            window.options.page.curr = curr;
            window.page = curr;
            window.limit = res.limit;
        },
        cols: [
            [{
                title: '会员编号',
                unresize: true,
                align: 'center',
                templet:function(d){
                    return '<div style="cursor:pointer;text-decoration:underline;color:#6590DC" lay-event="user" >'+d.number+'</div>';
                },
                width:'15%'
            }, {
                title: '会员类型',
                unresize: true,
                align: 'center',
                templet:function(d){
                    switch(d.grade_type){
                        case 1 : return '包月'; break;
                        case 2 : return '半年'; break;
                        case 3 : return '包年'; break;
                    }
                },
                width:'15%'
            }, {
                field: 'price',
                title: '支付金额',
                unresize: true,
                align: 'center',
                width:'15%'
            }, {
                title: '支付方式',
                unresize: true,
                align: 'center',
                templet:function(d){
                    switch(d.pay_type){
                        case 0: return '余额';break;
                        case 1: return '微信';break;
                        case 2: return '支付宝';break;
                    }
                },
                width:'15%'
            }, {
                field: 'order_no',
                title: '订单编号',
                unresize: true,
                align: 'center',
                width: '25%'
            }, {
                field: 'pay_time',
                title: '支付时间',
                unresize: true,
                align: 'center',
                width:'15%'
            }]
        ],
    };
    window.tableIns = laytable.render(window.options);
    laytable.on('tool(data_table)', function(obj) {
        if (obj.event === 'edit') {
            layer_iframe('编辑购买会员记录表', 'edit?id=' + obj.data.id);
        } else if (obj.event === 'del') {
            _ajax_remove('确定删除该购买会员记录表吗?', 'before_upgrade', obj.data.id);
        }else if (obj.event === 'user') {
            layer_iframe('会员信息', '/before/user/index?id=' + obj.data.user_id);

        }
    });
});
